package com.lancoo.cvas.schedues;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.StrUtil;
import com.lancoo.cvas.entity.TaskInfo;
import com.lancoo.cvas.pojo.common.Deleted;
import com.lancoo.cvas.pojo.constant.GlobalConstant;
import com.lancoo.cvas.pojo.response.basicPlatform.SubSystemsMainServer;
import com.lancoo.cvas.service.TaskInfoService;
import com.lancoo.cvas.service.YunService;
import com.lancoo.cvas.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

@Component
@Slf4j
@EnableAsync(proxyTargetClass = true)
public class InitTeacher {


    @Resource
    private TaskInfoService taskInfoService;

    @Resource
    private YunService yunService;

    @Resource
    private RedisUtil redisUtil;


    @Scheduled(cron = "0 0 2 * * ?")
    public void initTeacher() {
        List<TaskInfo> taskInfoList = taskInfoService.lambdaQuery().eq(TaskInfo::getDeleted, Deleted.NOT.getCode()).list();
        if (CollUtil.isNotEmpty(taskInfoList)) {
            taskInfoList.forEach(o -> {
                yunService.syncTeacher(o.getTaskId(), o.getSchoolId(), o.getTerm());
            });
            log.info("教师更新成功");

            redisUtil.del("cvas:com.lancoo.cvas.mapper.TeacherMapper");
        } else {
            log.error("没有开课计划，不需要初始化教师信息");
        }
    }

}
